home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / mail110 / mail.c < prev    next >
C/C++ Source or Header  |  1994-02-14  |  5KB  |  290 lines

  1. //=========================================================
  2. //
  3. //    mail.c
  4. //
  5. //    void mailto(char *xuser, char *xfile);
  6. //
  7. //    void replyto(int msg);
  8. //
  9. //    void forwardto(int msg, char *xuser);
  10. //
  11. //=========================================================
  12.  
  13. // $Id: mail.c,v 1.3 1994/02/14 23:37:32 gbj Exp user $
  14.  
  15. /*
  16. $Log: mail.c,v $
  17.  * Revision 1.3  1994/02/14  23:37:32  gbj
  18.  * Incorporated changes for Alec Jones's outgoing mail log.
  19.  *
  20.  * Revision 1.2  1994/02/08  23:32:02  gbj
  21.  * First public release.
  22.  *
  23.  * Revision 1.1  1994/02/08  03:15:10  gbj
  24.  * Initial revision
  25.  *
  26. */
  27.  
  28. #include "mailer.h"
  29.  
  30. static char subject[128];
  31. static char cmd[128];
  32.  
  33. void mailto(char *xuser, char *xfile)
  34. {
  35.     int res, c, done;
  36.     
  37.     if (user == NULL)
  38.     {
  39.         fprintf(stderr, "mailto: No user!\n");
  40.         return;
  41.     }
  42.     if (*user == '\0')
  43.     {
  44.         fprintf(stderr, "mailto: No user!\n");
  45.         return;
  46.     }
  47.     
  48.     subject[0]='\0';
  49.     while (subject[0] == '\0')
  50.     {
  51.         printf("Subject: ");
  52.         gets(subject);
  53.     }
  54.     
  55.     if (xfile == NULL)
  56.         res=setpost(xuser, subject, "");
  57.     else if (*xfile == '\0')
  58.         res=setpost(xuser, subject, "");
  59.     else
  60.         res=setpost(xuser, subject, xfile);
  61.         
  62.     if (res != 0)
  63.     {
  64.         remove(txt);
  65.         remove(wrk);
  66.         *txt='\0';
  67.         *wrk='\0';
  68.         return;
  69.     }
  70.     
  71.     done=FALSE;
  72.     while (!done)
  73.     {
  74.         printf("(P)ost, (E)dit or (A)bandon: ");
  75.         c=toupper(getche());
  76.         putch('\r');
  77.         putch('\n');
  78.         if (c == 'P')
  79.         {
  80.             if (*log)
  81.                 append_to_log(txt);
  82.             done=TRUE;
  83.         }
  84.         else if (c == 'E')
  85.         {
  86.             sprintf(cmd, "%s %s", edit, txt);
  87.             res=system(cmd);
  88.             if (res == -1)
  89.             {
  90.                 perror("mailto");
  91.                 fprintf(stderr, 
  92.                     "mailto: Couldn't run editor, command line is:\n");
  93.                 fprintf(stderr, "%s\n", cmd);
  94.             }
  95.             done=FALSE;
  96.         }
  97.         else if (c == 'A') 
  98.         {
  99.             remove(txt);
  100.             remove(wrk);
  101.             done=TRUE;
  102.         }
  103.     }
  104.     *txt='\0';
  105.     *wrk='\0';
  106.     return;
  107. }
  108.  
  109. void replyto(int msg)
  110. {
  111.     char subject[128], tsubject[128], *ts;
  112.     int res, c, done, quote, copy_msg;
  113.  
  114.     if (msg < 0 || msg > maxmsgno)
  115.     {
  116.         printf("\nMessage %d does not exist\n\n", msg);
  117.         return;
  118.     }
  119.     
  120.     strcpy(tmp, "post.$$$");
  121.     done=FALSE;
  122.     while (!done)
  123.     {
  124.         printf("Quote the message (Y/N)? ");
  125.         c=getche();
  126.         putchar('\r');
  127.         putchar('\n');
  128.         if (toupper(c) == 'Y')
  129.         {
  130.             quote=TRUE;
  131.             done=TRUE;
  132.         }
  133.         else if (toupper(c) == 'N')
  134.         {
  135.             quote=FALSE;
  136.             done=TRUE;
  137.         }
  138.         else
  139.             done=FALSE;
  140.     }
  141.  
  142.     if (quote)
  143.         copy_msg=TRUE;
  144.     else
  145.         copy_msg=FALSE;    
  146.     res=tmp_msg(msg, tmp, quote, copy_msg); 
  147.     if (res)
  148.     {
  149.         remove(tmp);
  150.         return;
  151.     }
  152.  
  153.     strcpy(tsubject, mailix[msg].subject);
  154.     ts=strstr(tsubject, "Re:");
  155.     if (ts == NULL)
  156.         ts=strstr(tsubject, "RE:");
  157.     if (ts == NULL)
  158.         ts=strstr(tsubject, "re:");
  159.     if (ts == NULL)
  160.         ts=strstr(tsubject, "rE:");
  161.     if (ts == NULL)
  162.         sprintf(subject, "Re: %s", tsubject);
  163.     else
  164.     {
  165.         *ts++='R';        // Make sure it says "Re:"
  166.         *ts='e';
  167.         sprintf(subject, "%s", tsubject);
  168.     }
  169.  
  170.     res=setpost(mailix[msg].replyto, subject, tmp); 
  171.     remove(tmp);
  172.     *tmp='\0';    
  173.     if (res != 0)
  174.     {
  175.         remove(txt);
  176.         remove(wrk);
  177.         *txt='\0';
  178.         *wrk='\0';
  179.         return;
  180.     }
  181.     
  182.     done=FALSE;
  183.     while (!done)
  184.     {
  185.         printf("(P)ost, (E)dit or (A)bandon: ");
  186.         c=toupper(getche());
  187.         putch('\r');
  188.         putch('\n');
  189.         if (c == 'P')
  190.         {
  191.             if (*log)
  192.                 append_to_log(txt);
  193.             done=TRUE;
  194.         }
  195.         else if (c == 'E')
  196.         {
  197.             sprintf(cmd, "%s %s", edit, txt);
  198.             res=system(cmd);
  199.             if (res == -1)
  200.             {
  201.                 perror("replyto");
  202.                 fprintf(stderr, 
  203.                     "replyto: Couldn't run editor, command line is:\n");
  204.                 fprintf(stderr, "%s\n", cmd);
  205.             }
  206.             done=FALSE;
  207.         }
  208.         else if (c == 'A') 
  209.         {
  210.             remove(txt);
  211.             remove(wrk);
  212.             done=TRUE;
  213.         }
  214.     }
  215.     *txt='\0';
  216.     *wrk='\0';
  217.     return ;
  218. }
  219.  
  220. void forwardto(int msg, char *xuser)
  221. {
  222.     char subject[128];
  223.     int res, c, done;
  224.     
  225.     if (msg < 0 || msg > maxmsgno)
  226.     {
  227.         printf("\nMessage %s does not exist\n\n", msg);
  228.         return;
  229.     }
  230.     strcpy(tmp, "post.$$$");
  231.     done=FALSE;
  232.     res=tmp_msg(msg, tmp, FALSE, TRUE); 
  233.     if (res)
  234.     {
  235.         remove(tmp);
  236.         return;
  237.     }
  238.  
  239.     sprintf(subject, "Fwd: %s", mailix[msg].subject);
  240.     res=setpost(xuser, subject, tmp); 
  241.     remove(tmp);
  242.     *tmp='\0';    
  243.     if (res != 0)
  244.     {
  245.         remove(txt);
  246.         remove(wrk);
  247.         *txt='\0';
  248.         *wrk='\0';
  249.         return;
  250.     }
  251.     
  252.     done=FALSE;
  253.     while (!done)
  254.     {
  255.         printf("(P)ost, (E)dit or (A)bandon: ");
  256.         c=toupper(getche());
  257.         putch('\r');
  258.         putch('\n');
  259.         if (c == 'P')
  260.         {
  261.             if (*log)
  262.                 append_to_log(txt);
  263.             done=TRUE;
  264.         }
  265.         else if (c == 'E')
  266.         {
  267.             sprintf(cmd, "%s %s", edit, txt);
  268.             res=system(cmd);
  269.             if (res == -1)
  270.             {
  271.                 perror("replyto");
  272.                 fprintf(stderr, 
  273.                     "replyto: Couldn't run editor, command line is:\n");
  274.                 fprintf(stderr, "%s\n", cmd);
  275.             }
  276.             done=FALSE;
  277.         }
  278.         else if (c == 'A') 
  279.         {
  280.             remove(txt);
  281.             remove(wrk);
  282.             done=TRUE;
  283.         }
  284.     }
  285.     *txt='\0';
  286.     *wrk='\0';
  287.  
  288.     return;
  289. }
  290.